1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
"use client"
import { useEffect, useState } from "react"
import { AvlTable } from "@/lib/avl/table/avl-table"
import { AvlRegistrationArea } from "@/lib/avl/table/avl-registration-area"
import { getAvlLists } from "@/lib/avl/service"
import { AvlListItem } from "@/lib/avl/types"
import { toast } from "sonner"
import { InformationButton } from "@/components/information/information-button"
import { useTranslation } from "@/i18n/client"
import { useParams } from "next/navigation"
interface AvlPageClientProps {
initialData: AvlListItem[]
}
export function AvlPageClient({ initialData }: AvlPageClientProps) {
const [avlListData, setAvlListData] = useState<AvlListItem[]>(initialData)
const [isLoading, setIsLoading] = useState(false)
const [registrationMode, setRegistrationMode] = useState<'standard' | 'project' | null>(null)
const params = useParams<{lng: string}>()
const lng = params?.lng ?? 'ko'
const {t} = useTranslation(lng, 'menu')
// 초기 데이터 설정
useEffect(() => {
setAvlListData(initialData)
}, [initialData])
// AVL 리스트 데이터 로드 (클라이언트에서 추가 로드 시 사용)
const loadAvlListData = async () => {
try {
setIsLoading(true)
// 기본 파라미터로 전체 데이터 조회
const result = await getAvlLists({
page: 1,
perPage: 100, // 충분한 수량으로 조회
sort: [{ id: "createdAt", desc: true }],
flags: [],
filters: [],
joinOperator: "and",
search: "",
isTemplate: "false",
constructionSector: "",
projectCode: "",
shipType: "",
avlKind: "",
htDivision: "H",
rev: "",
})
setAvlListData(result.data)
} catch (error) {
console.error("AVL 리스트 로드 실패:", error)
toast.error("AVL 리스트를 불러오는데 실패했습니다.")
setAvlListData([])
} finally {
setIsLoading(false)
}
}
// 리프레시 핸들러
const handleRefresh = async () => {
await loadAvlListData()
toast.success("AVL 리스트가 새로고침되었습니다.")
}
// 등록 모드 변경 핸들러
const handleRegistrationModeChange = (mode: 'standard' | 'project') => {
setRegistrationMode(mode)
}
// 행 선택 핸들러 (현재는 사용하지 않지만 향후 확장 대비)
const handleRowSelect = () => {}
return (
<div className="min-h-screen">
{/* info button and header section */}
<div className="flex items-center gap-2 mt-2">
<h2 className="text-2xl font-bold tracking-tight">
{t('menu.vendor_management.avl_management')}
</h2>
<InformationButton pagePath="evcp/avl" />
</div>
{/* 상단: AVL 목록 */}
<div className="p-4">
<AvlTable
data={avlListData}
onRefresh={handleRefresh}
isLoading={isLoading}
onRegistrationModeChange={handleRegistrationModeChange}
onRowSelect={handleRowSelect}
/>
</div>
{/* 하단: AVL 등록 */}
<div className="p-4 overflow-x-auto">
<AvlRegistrationArea disabled={registrationMode === null} />
</div>
</div>
)
}
|